import sys

from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QLineEdit, QPushButton, QMessageBox, QFrame

'''
QFrame()  记得 resize(300,200)大小
QApplication.instance().exit()  # 退出所有应用程序

提示框的2种方式：
QMessageBox.information(self, '消息', '用户名：' + self.leUsername.text() + ',密码：' + self.lePassword.text(), QMessageBox.Ok)
msgbox = QMessageBox(QMessageBox.Information, '帮助', '欢迎使用本系统', QMessageBox.Ok, self)
msgbox.show()

# 隐藏最大化最小化窗口,只显示关闭按钮
self.setWindowFlags(Qt.WindowCloseButtonHint)
'''


class MyClass(QMainWindow):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle('刘金玉编程教程')
        self.setWindowIcon(QIcon('./img/msn.ico'))
        self.setGeometry(800, 370, 400, 300)

        myframe = QFrame(self)
        myframe.resize(400, 300)  # 指定大小，否则太小看不见其他控件
        myframe.move(50, 50)

        lba1 = QLabel('用户名：', myframe)
        lba1.move(0, 3)
        lba2 = QLabel('密  码：', myframe)
        lba2.move(0, 33)
        self.leUsername = QLineEdit(myframe)
        self.leUsername.move(50, 0)
        self.lePassword = QLineEdit(myframe)
        self.lePassword.move(50, 30)
        self.lePassword.setEchoMode(QLineEdit.Password)  # 密码输入模式
        btnLogin = QPushButton('登陆', myframe)
        btnLogin.move(20, 80)
        btnLogin.clicked.connect(self.myDo)
        btnQuit = QPushButton('退出', myframe)
        btnQuit.move(100, 80)
        btnQuit.clicked.connect(self.myDo)

        # 隐藏最大化最小化窗口,只显示关闭按钮
        self.setWindowFlags(Qt.WindowCloseButtonHint)

        self.show()

    def myDo(self):
        source = self.sender()
        if source.text() == '登陆':
            QMessageBox.information(self, '消息', '用户名：' + self.leUsername.text() + ',密码：' + self.lePassword.text(),
                                    QMessageBox.Ok)
        elif source.text() == '退出':
            QApplication.instance().exit()  # 退出所有应用程序


if __name__ == '__main__':
    app = QApplication(sys.argv)
    myf = MyClass()
    app.exec_()
